/*     */ package com.qmsk.business.task.apply.controller;
/*     */ 
/*     */ import com.qmsk.business.sys.basic.UploadFileUtil;
/*     */ import com.qmsk.business.task.apply.dao.ApplyDao;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.file.GlobalParams;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"apply"})
/*     */ public class ApplyController
/*     */ {
/*  35 */   private static final Logger logger = Logger.getLogger(ApplyController.class);
/*     */ 
/*     */   @Autowired
/*     */   private ApplyDao dao;
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"insert/insertInfo"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/*  54 */       int nResult = 0;
/*  55 */       String sData = RequestUtils.getStringOfData(request);
/*  56 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*  57 */       String openId = null;
/*  58 */       String name = null;
/*  59 */       String mp = null;
/*  60 */       if ((p != null) && (p.isExistsInsertRows())) {
/*  61 */         GsonHeadOneRow g = (GsonHeadOneRow)p.getListInsertRows().get(0);
/*  62 */         g.autoAddHeadData("createdTime", new Date());
/*  63 */         openId = (String)g.getValueOfName("openId");
/*  64 */         name = (String)g.getValueOfName("name");
/*  65 */         mp = (String)g.getValueOfName("mp");
/*  66 */         nResult = this.dao.checkExistByMp(mp);
/*  67 */         if (nResult == 1) {
/*  68 */           ResponseUtils.setErrorMsgResponse("该手机号已使用", response);
/*  69 */           return;
/*     */         }
/*  71 */         nResult = this.dao.applyUpdates(p, "id");
/*  72 */         if (nResult > 0) {
/*  73 */           DbConnection.commit();
/*  74 */           WeiXinUtil.sendTextMessageOfMain("报名表确认\n尊敬的" + name + ":我们已经收到您的报名信息，感谢您的参与!", openId);
/*     */ 
/*  76 */           GsonHeadOneRow gs = (GsonHeadOneRow)p.getListInsertRows().get(0);
/*  77 */           Long id = ObjectComm.objectToLong(gs.getValueOfName("id"));
/*  78 */           String[] head = { "id" };
/*  79 */           Object[] data = { id };
/*  80 */           ResponseUtils.toGsonEbRst(head, data, response);
/*  81 */           return;
/*     */         }
/*  83 */         DbConnection.rollback();
/*     */       }
/*     */ 
/*  86 */       ResponseUtils.setSqlResultResponse(nResult, 
/*  87 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/*  88 */         response);
/*     */     } catch (Exception e) {
/*  90 */       logger.error(e);
/*  91 */       DbConnection.rollback();
/*  92 */       ResponseUtils.setErrorMsgResponse(
/*  93 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/*  94 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 111 */       int nResult = 0;
/* 112 */       String sData = RequestUtils.getStringOfData(request);
/* 113 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 114 */       if (p != null) {
/* 115 */         nResult = this.dao.applyUpdates(p);
/* 116 */         if (nResult > 0)
/* 117 */           DbConnection.commit();
/*     */         else {
/* 119 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 122 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 123 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 124 */         response);
/*     */     } catch (Exception e) {
/* 126 */       logger.error(e);
/* 127 */       DbConnection.rollback();
/* 128 */       ResponseUtils.setErrorMsgResponse(
/* 129 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 130 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 195 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 197 */       String[] strParams = id.split(",");
/* 198 */       int nResult = this.dao.deleteParams(strParams);
/* 199 */       if (nResult > 0) {
/* 200 */         DbConnection.commit();
/*     */       }
/*     */       else {
/* 203 */         DbConnection.rollback();
/*     */       }
/* 205 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 206 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 207 */         response);
/*     */     } catch (Exception e) {
/* 209 */       DbConnection.rollback();
/* 210 */       logger.error(e);
/* 211 */       ResponseUtils.setErrorMsgResponse(
/* 212 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 213 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"upload/images/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void uploadImage(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try
/*     */     {
/* 222 */       String path = GlobalParams.getGlobalParams().getApacheRoot() + 
/* 223 */         "ad/" + id + "/";
/* 224 */       String httpPath = GlobalParams.getGlobalParams().getApacheUrl() + 
/* 225 */         "ad/" + id + "/";
/*     */ 
/* 227 */       List<String> listFileName = new ArrayList();
/*     */ 
/* 229 */       UploadFileUtil.uploadFileOfRequest(request, response, path, 
/* 230 */         listFileName, "imageUrl");
/*     */ 
/* 232 */       String paths = "";
/* 233 */       if (listFileName != null) {
/* 234 */         for (String str : listFileName) {
/* 235 */           if (StringUtils.isNotEmpty(str)) {
/* 236 */             paths = httpPath + str;
/*     */           }
/*     */         }
/*     */       }
/* 240 */       if (StringUtils.isNotEmpty(paths)) {
/* 241 */         int sResult = 0;
/* 242 */         sResult = this.dao.updateImage(paths, id);
/* 243 */         if (sResult > 0) {
/* 244 */           this.dao.commit();
/* 245 */           ResponseUtils.setSuccessResponse(paths, response);
/* 246 */           return; }
/* 247 */         this.dao.rollback();
/* 248 */         ResponseUtils.setErrorMsgResponse(
/* 249 */           RequestUtils.getUploadPicErrorMessage(request), 
/* 250 */           response);
/*     */ 
/* 252 */         return; }
/* 253 */       this.dao.rollback();
/* 254 */       ResponseUtils.setErrorMsgResponse(
/* 255 */         RequestUtils.getUploadPicErrorMessage(request), 
/* 256 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 259 */       logger.error(e);
/* 260 */       ResponseUtils.setErrorMsgResponse(
/* 261 */         RequestUtils.getUploadPicErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.task.apply.controller.ApplyController
 * JD-Core Version:    0.5.3
 */